package assignment3;
/**
 * StarListGUI
 * 
 * @author
 * 
 */



import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class StarListGUI extends JFrame implements ActionListener {
	public static void main(String[] a){
		new StarListGUI("Stars");
	}
	
	/*
	 * Data members
	 */
	private static final long serialVersionUID = 1L;
	private final int FRAME_X=100, FRAME_Y=100, FRAME_WIDTH=400,  FRAME_HEIGHT=300;
	private final int SCROLL_X=30, SCROLL_Y=30, SCROLL_WIDTH=300, SCROLL_HEIGHT=200;
	private final int SORT_X=30,   SORT_Y=235,  SORT_WIDTH=100,   SORT_HEIGHT=30;
	private String SORT_STRING = "Sort";
	private String SHUFFLE_STRING = "Shuffle";
	private JList<Star> listview;
	private JScrollPane scroll;
	
	private JButton sort;

	/**
	 * StarListGUI constructor
	 * 
	 * @param title
	 *
	 */
	public StarListGUI(String title) {
		super(title);
		setBounds(FRAME_X, FRAME_Y, FRAME_WIDTH, FRAME_HEIGHT);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		setLayout( null );
		
		/*
		 * Data that will be used as the "List Model"
		 */
		Star[] stars = new Star[1];
		DefaultListModel<Star> listmodel = new DefaultListModel<Star>();
		for (Star s : stars)
			listmodel.addElement( s );

		/*
		 * Now that the data is available, set up GUI elements to display it.
		 */
		listview = new JList<Star>( listmodel );
		listview.setVisible(true);
		scroll = new JScrollPane( listview );
		scroll.setBounds(SCROLL_X, SCROLL_Y, SCROLL_WIDTH, SCROLL_HEIGHT);
		add( scroll );
		
		sort = new JButton( SORT_STRING );
		sort.addActionListener( this );
		sort.setBounds(SORT_X, SORT_Y, SORT_WIDTH, SORT_HEIGHT);
		add(sort);

		
		setVisible( true );
	} // end StarListGUI constructor

	/**
	 * actionPerformed - 
	 * 
	 * 
	 */
	public void actionPerformed(ActionEvent ae) {
		Object source = ae.getSource();
		if (source.equals(sort)){
			if (sort.getText().equals( SORT_STRING )){
				sort.setText(SHUFFLE_STRING);
				/*
				 * Sort
				 */
				//Collections.sort( listmodel );
			} else {
				if (sort.getText().equals( SHUFFLE_STRING )){
					sort.setText( SORT_STRING );
				/*
				 * Shuffle
				 */
				}
				
			}
		}	
	} // end actionPerformed
}
